package com.zrt.view;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@Controller
public class Login extends JFrame implements ActionListener {

    JLabel jl1, jl2, jl3, jl4;
    JTextField jtf;
    JPasswordField jpf;
    JButton jb;
    @Autowired
    private Management management;
    public static void main(String[] args) {
        ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
        Login mylogin= (Login) ctx.getBean("login");
        mylogin.myLogin();
    }

    public void myLogin() {

        jl1 = new JLabel(new ImageIcon(getClass().getResource("/images/1.jpg")));
        jl1.setBounds(0,0,600,238);
        add(jl1);

        jl2 = new JLabel("账   号");
        jl2.setBounds(190,280,100,30);
        jl2.setFont(new Font("宋体",Font.BOLD,18));
        add(jl2);

        jtf = new JTextField();
        jtf.setBounds(300,280,180,30);
        jtf.setBorder(BorderFactory.createLoweredBevelBorder());
        add(jtf);

        jl3 = new JLabel("密   码");
        jl3.setBounds(190,330,100,30);
        jl3.setFont(new Font("宋体",Font.BOLD,18));
        add(jl3);

        jpf = new JPasswordField();
        jpf.setBounds(300,330,180,30);
        jpf.setBorder(BorderFactory.createLoweredBevelBorder());
        add(jpf);

        jb = new JButton("登   录");
        jb.setFont(new Font("宋体",Font.BOLD,20));
        jb.setBackground(Color.CYAN);
        jb.setBounds(230,400,120,40);
        jb.addActionListener(this);
        add(jb);

        jl4 = new JLabel(new ImageIcon(getClass().getResource("/images/2.gif")));
        jl4.setBounds(20,248,150,150);
        add(jl4);


        setTitle("电子科技大学成都学院财务管理系统");
        setLayout(null);
        setSize(600, 500);
        setLocation(500, 100);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setVisible(true);
    }
    //登录
    @Override
    public void actionPerformed(ActionEvent e) {
        this.dispose();
        management.myManagement();
    }
}
